layui.use(['jquery','layer','form','table','laydate','upload'],function() {
    var $ = layui.$, layer = layui.layer, form = layui.form, table = layui.table, laydate = layui.laydate,
        upload = layui.upload;


//获取当前时间
    var myDate = new Date();
    var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
    var myMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
    var myToday = myDate.getDate(); //获取当前日(1-31)
    var myDay = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
    var myHour = myDate.getHours(); //获取当前小时数(0-23)
    var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
    var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
    var newTime = myYear+'-'+myMonth+'-'+myToday+' '+myHour+':'+myMinute+':'+mySecond;
    //获取申请列表 赵 22/1/14
    getCreatorApply()
    function getCreatorApply(){
        $.ajax({
            url: '/user/getCreatorApply'
            ,data: {'result': 1}
            ,dataType: 'json'
            ,success:function(data){
                tableRender(data.data);
            }
        });
    }

    //渲染表格 赵 22/1/14
    tableRender = function tableRender(data){
        table.render({
            elem: '#layuiTbale'
            ,data: data
            ,limit: 10
            ,toolbar: '#toolutil'
            ,page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
                ,limits:[10,15,20]
                ,first: true
                ,last: true
            }
            ,cols: [[
                {checkbox: true}
                ,{type: 'numbers',title: '序号',align: 'center'}
                ,{field: 'fullName',title: '用户姓名',align: 'center'}
                ,{field: 'roleName',title: '申请职位',align: 'center'}
                ,{field: 'phone',title: '电话',align: 'center'}
                ,{field: 'applyDate',title: '申请时间',align: 'center'}
                ,{field: 'email',title: '邮箱',align: 'center'}
                ,{title: '操作',align: 'center',templet:function(data){
                    return '<a style="color: #009688" onclick="see('+data.userId+')">查看</a> ' +
                        '<a style="color: #009688" onclick="adopt('+data.userId+')">通过</a> ' +
                        '<a style="color: #009688" onclick="reject('+data.userId+')">驳回</a>'
                    }}
            ]]
        });
    }

    //普通检索
    form.on('submit(sub)',function (data) {
        var user =data.field;
        $.ajax({
            url: '/user/getCreatorApply'
            ,data: {
                'fullName': user.fullName
                ,'account': user.account
                ,'applyDate': user.applyDate
                ,'result': 1
            }
            ,dataType: 'json'
            ,success:function(data){
                tableRender(data.data);
            }
        });
    });

    //高级检索
    advancedRetrieval = function advancedRetrieval(){
        layer.open({
            type: 2
            ,title: '高级检索'
            ,content: 'popup/apply-list-advancedRetrieval.html'
            ,area: ['650px','330px']
        });
    }
    //查看 赵 22/1/14
    see = function see(userId){
        $('#userId').val(userId);
        layer.open({
            type: 2
            ,title: '查看用户详情信息'
            ,content: 'popup/apply-list-see.html'
            ,area: ['960px','600px']
        });
    }

    //申请通过 赵 22/1/14
    adopt = function adopt(userId){
        layer.open({
            title: '申请通过'
            ,content: '<textarea name="reason" class="layui-textarea" placeholder="请输入通过缘由"></textarea>'
            ,btn: ['确定','取消']
            ,yes:function(index){
                var reason = $('textarea[naem=reason]').val();
                //改变审核状态
                $.ajax({
                    url: '/user/updateApply'
                    ,data: {
                        'result': 2
                        ,'remarks': reason
                        ,'implementId': 1
                        ,'implementDate': newTime
                        ,'launchId': userId
                    }
                    ,dataType: 'json'
                    ,success:function(data){

                        $.ajax({
                            url: '/user/addJurisdiction'
                            ,data: {
                                'userId': userId
                                ,'trId': 1
                                ,'type': 2
                                ,'remarks': '通过申请'
                                ,'createId': 1
                                ,'createDate': newTime
                                ,'updateId': 1
                                ,'updateDate': newTime
                            }
                            ,dataType: 'json'
                            ,success:function(data){
                                layer.close(index);
                                getCreatorApply();
                                layer.msg('已通过申请');
                            }
                        })
                    }
                });
            }
            ,btn2:function(index){
                layer.close(index);
            }
        })
    }

    //申请驳回 赵 22/1/14
    reject = function reject(userId){
        layer.open({
            title: '申请驳回'
            ,content: '<textarea name="reason" class="layui-textarea" placeholder="请输入驳回缘由"></textarea>'
            ,btn: ['确定','取消']
            ,yes:function(index){
                var reason = $('textarea[naem=reason]').val();
                //改变审核状态
                $.ajax({
                    url: '/user/updateApply'
                    ,data: {
                        'result': 3
                        ,'remarks': reason
                        ,'implementId': 1
                        ,'implementDate': newTime
                        ,'launchId': userId
                    }
                    ,dataType: 'json'
                    ,success:function(data){
                        layer.close(index);
                        layer.msg('已驳回申请');
                    }
                });
            }
            ,btn2:function(index){
                layer.close(index);
            }
        })
    }


//刷新 22/1/14 赵
refresh = function refresh(){
    location.reload();
}


});
//返回首页
function backOff(){
    parent.jumpSystemHome();
}